package com.fks.fks_service.mapper;

import com.fks.fks_service.pojo.MorningAndNightTime;
import com.fks.fks_service.pojo.ShopOrder;
import com.fks.fks_service.utils.ProxyCommissionRecordSql;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface ShopOrderMapper {

    @Select("select * from fks_shop_order where id=#{shopOrderId}")
    ShopOrder getShopOrderById(int shopOrderId);

    @Insert("insert into fks_shop_order (orderNo,uid ,realName ,realAge ,realGender " +
            ",shopId ,shopTitle ,shopIntroduction ,shopBannerImages ,shopDetailImages " +
            ",shopScore ,createTime ,status ,cancellationReason ,isDelete ,notes ,adminNotes " +
            ",categoryName1 ,categoryName2 ,categoryName3 ,comment) " +
            "value(#{orderNo},#{uid},#{realName},#{realAge},#{realGender}" +
            ",#{shopId},#{shopTitle},#{shopIntroduction},#{shopBannerImages},#{shopDetailImages}" +
            ",#{shopScore},#{createTime},#{status},#{cancellationReason},#{isDelete},#{notes}" +
            ",#{adminNotes},#{categoryName1},#{categoryName2},#{categoryName3},#{comment})")
    int addShopOrder(ShopOrder shopOrder);

    @Update("update fks_shop_order set status='1',payTime=#{nowTime} where orderNo=#{orderNo}")
    int updateStatus(String orderNo,String nowTime);

    @Update("update fks_shop_order set status=#{status} where orderNo=#{orderNo}")
    int updateStatus2(ShopOrder order);

    @Select("select * from fks_shop_order where orderNo=#{orderNo}")
    ShopOrder getShopOrderId(String orderNo);

    @Select("select * from fks_shop_order where isDelete='0' and uid=#{userId} and status!='0' and status!='-1' order by" +
            " createTime desc limit #{page},#{pageSize}")
    List<ShopOrder> getOrderList(int userId, int page, int pageSize);

    @Select("select * from fks_shop_order where isDelete=0 and uid=#{userId} and status=#{status} order by" +
            " createTime desc limit #{page},#{pageSize}")
    List<ShopOrder> getUserOrderListByStatus(int userId, int page, int pageSize, int status);

    @SelectProvider(type = ProxyCommissionRecordSql.class, method = "selectShopOrderListNumber")
    int getOrderListByStatusNumber(@Param("merchantUserId") int merchantUserId, @Param("id") int id
            , @Param("shopTitle") String shopTitle);

    @SelectProvider(type = ProxyCommissionRecordSql.class, method = "selectShopOrderListNumber2")
    int getOrderListByStatusNumber2(@Param("merchantUserId") int merchantUserId, @Param("id") int id
            , @Param("shopTitle") String shopTitle,@Param("status") String status);

    @SelectProvider(type = ProxyCommissionRecordSql.class, method = "selectShopOrderList")
    List<ShopOrder> getOrderListByStatus(@Param("merchantUserId") int merchantUserId,@Param("id") int id
            ,@Param("shopTitle") String shopTitle
            ,@Param("page") int page,@Param("pageSize") int pageSize);

    @SelectProvider(type = ProxyCommissionRecordSql.class, method = "selectShopOrderList2")
    List<ShopOrder> getOrderListByStatus2(@Param("merchantUserId") int merchantUserId,@Param("id") int id
            ,@Param("shopTitle") String shopTitle
            ,@Param("page") int page,@Param("pageSize") int pageSize,@Param("status") String status);

    @Update("update fks_shop_order set isDelete=1 where id=#{id}")
    int deleteOrder(int id);

    @Select("select * from fks_shop_order where status=#{status}")
    List<ShopOrder> getShopOrderListByStatusAndUserId(String status);

    @Select("select count(*) from fks_shop_order where payTime>=#{time.morning} and payTime<=#{time.night}")
    int getPayNumber(MorningAndNightTime time);

    @Select("select count(*) from fks_shop_order where payTime>=#{time.lastMorning} and payTime<=#{time.lastNight} ")
    int getPayNumber2(MorningAndNightTime time);

    @Select("select payTime from fks_shop_order where payTime>=#{time.morning} and payTime<=#{time.night}")
    List<String> getPayNumberList(MorningAndNightTime time);

    @Select("select * from fks_shop_order where payTime>=#{time.morning} and payTime<=#{time.night} ")
    List<ShopOrder> getOrderListByTime(MorningAndNightTime time);

    @Select("select * from fks_shop_order where orderNo=#{orderNo}")
    ShopOrder getShopOrder(String orderNo);

    @Update("update fks_shop_order set adminNotes=#{adminNotes} where id=#{shopOrderId}")
    int updateAdminNotes(Integer shopOrderId, String adminNotes);

    @Update("update fks_shop_order set status='2' where orderNo=#{orderNo}")
    int completeService(String orderNo);
}
